<?php

namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Orderall;
use App\UserCoin;
use Illuminate\Support\Facades\DB;

class OrderController extends Controller
{
    protected $wechat;

    public function __construct()
    {
        $this->wechat = app('wechat');
    }

    public function notify(Orderall $order)
    {
        $user = $order->user;
        $user->update(['status' => DB::raw('status|8')]);
        switch ($order->type) {
            case 1:
                //product
                $product = $order->product;
                switch ($product->type) {
                    case 1:
                        $key = '0-' . $user->id . '-' . $product->value . '-' . $order->id . '-1';
                        //金币日志
                        UserCoin::log(0, $user->id, UserCoin::TYPE_JB, $product->value, '充值', $key, 'in');
                        break;
                }
                break;
            case 2:
                //mall
                $mallOrder = \App\Order::find($order->related_id);
                $mallOrder->status = 1;
                $mallOrder->save();
                break;
        }
    }
}
